package cn.iocoder.yudao.module.system.controller.admin.ai;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.ai.vo.*;
import cn.iocoder.yudao.module.system.service.ai.AiVolunteerRecommendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * 管理后台 - AI智能推荐控制器
 *
 * @author 芋道源码
 */
@Tag(name = "管理后台 - AI智能推荐")
@RestController
@RequestMapping("/system/ai-recommend")
@Validated
@Slf4j
public class AiRecommendController {

    @Resource
    private AiVolunteerRecommendService aiVolunteerRecommendService;

    @PostMapping("/volunteer")
    @Operation(summary = "AI智能选志愿推荐")
    public CommonResult<AiVolunteerRecommendRespVO> recommendVolunteers(
            @Valid @RequestBody AiVolunteerRecommendReqVO reqVO) {
        log.info("收到AI智能选志愿请求：省份={}, 年份={}, 分数={}, 位次={}, 学校名称={}", 
                reqVO.getProvince(), reqVO.getYear(), reqVO.getScore(), reqVO.getRanks(), reqVO.getUniversityName());
        
        try {
            AiVolunteerRecommendRespVO respVO = aiVolunteerRecommendService.recommendVolunteers(reqVO);
            return success(respVO);
        } catch (Exception e) {
            log.error("AI智能选志愿推荐失败", e);
            throw new RuntimeException("推荐服务异常：" + e.getMessage());
        }
    }

    @PostMapping("/volunteer/count")
    @Operation(summary = "AI智能选志愿数量统计", description = "统计可填专业的数量分布（冲刺/稳妥/保底）以及所属学校的类型分布（985/211/双一流/教育部直属/公办/民办）")
    public CommonResult<AiVolunteerCountRespVO> countVolunteers(
            @Valid @RequestBody AiVolunteerRecommendReqVO reqVO) {
        log.info("收到AI智能选志愿数量统计请求：省份={}, 年份={}, 分数={}, 位次={}, 学校名称={}", 
                reqVO.getProvince(), reqVO.getYear(), reqVO.getScore(), reqVO.getRanks(), reqVO.getUniversityName());
        
        try {
            AiVolunteerCountRespVO respVO = aiVolunteerRecommendService.countVolunteers(reqVO);
            return success(respVO);
        } catch (Exception e) {
            log.error("AI智能选志愿数量统计失败", e);
            throw new RuntimeException("数量统计服务异常：" + e.getMessage());
        }
    }

    @PostMapping("/volunteer/majors")
    @Operation(summary = "AI智能推荐专业列表")
    public CommonResult<AiMajorRecommendRespVO> recommendMajors(
            @Valid @RequestBody AiMajorRecommendReqVO reqVO) {
        log.info("收到AI智能推荐专业列表请求：省份={}, 年份={}, 招生代码={}, 专业组={}", 
                reqVO.getProvince(), reqVO.getYear(), reqVO.getRecruitCode(), reqVO.getUniversityMajorGroup());
        
        try {
            AiMajorRecommendRespVO respVO = aiVolunteerRecommendService.recommendMajors(reqVO);
            return success(respVO);
        } catch (Exception e) {
            log.error("AI智能推荐专业列表失败", e);
            throw new RuntimeException("推荐专业列表服务异常：" + e.getMessage());
        }
    }

    //提供将某个专业组加入到我的目标接口
    

}
